﻿using System;
using Cinemachine;
using UnityEngine;
using UnityEngine.Rendering.Universal;
//using Yoozoo.Core.Editor.Utility;
using Yoozoo.Mars.Got;
using ShadowResolution = UnityEngine.Rendering.Universal.ShadowResolution;


namespace Yoozoo.Core.Common
{
    [RequireComponent(typeof(Light))]
    public class LightQualityListener : 
        QualityListenerMono<LightQualityListener.LightQualitySetting>
    {
        [Serializable]
        public class LightQualitySetting : QualitySetting
        {
            public float lightIntensity;
            public Color lightColor;
            [Range(0,1)]
            public float shadowStrenth = 1;
            

            public void Apply(Light light)
            {
                light.intensity = this.lightIntensity;
                light.color = this.lightColor;
                light.shadowStrength = this.shadowStrenth;

                // if (controllerFrustum)
                // {
                //     if (drivenCamera!=null)
                //     {
                //         foreach (var childCamera in drivenCamera.ChildCameras)
                //         {
                //             CinemachineVirtualCamera child = childCamera as CinemachineVirtualCamera;
                //             if (child)
                //             {
                //                 child.m_Lens.NearClipPlane = nearPlaneDistance;
                //                 child.m_Lens.FarClipPlane = farPlaneDistance;
                //                 child.m_Lens.FieldOfView = fov;
                //             }
                //         }
                //     }
                //     else
                //     {
                //         camera.nearClipPlane = nearPlaneDistance;
                //         camera.farClipPlane = farPlaneDistance;
                //         camera.fieldOfView = fov;
                //     }
                // }

            }


        }
        
        [SerializeField]
        private Light _light;

        protected override void OnEnable()
        {
            base.OnEnable();
        }

        public override void ChangeQualitySetting(LightQualitySetting qualitySetting)
        {
            if (_light == null) _light = GetComponent<Light>();

            qualitySetting.Apply(_light);
        }

    
    }
}